package com.boylegu.springboot_vue.service.impl;

import com.boylegu.springboot_vue.dao.StudentsRepository;
import com.boylegu.springboot_vue.entities.Students;
import com.boylegu.springboot_vue.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentsRepository studentsRepository;

    @Override
    public void deleteById(String id) {
        studentsRepository.delete(id);
    }

    public Students save(Students student) {
        return studentsRepository.save(student);
    }

    @Override
    public Page<Students> findAll(Pageable page) {
        Page<Students> results = this.studentsRepository.findAll(page);
        return results;
    }

    @Override
    public List<Students> findAll() {
        return studentsRepository.findAll();
    }

    @Override
    public Students findById(String id) {
        return studentsRepository.findById(id);
    }

    public int count() throws Exception {
        long size = studentsRepository.count();
        int count = Integer.valueOf(String.valueOf(size));
        return count;
    }

}
